﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Services;
using IntelligentAgriculture.WebAPI.Application.Command.UnitCommand;
using IntelligentAgriculture.WebAPI.Application.CommandHandler.SheepCommandHandler;
using MediatR;
using System.ComponentModel.Design;
using Unit = IntelligentAgriculture.Domain.Entity.Unit;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.UnitCommandHandler
{
    public class UnitCreateCommandHandler : IRequestHandler<UnitCreateCommand, Results<int>>
    {
    

        private readonly IUnitService unitService;
        private readonly ILogger<UnitCreateCommandHandler> logger;
        public UnitCreateCommandHandler(IUnitService unitService, ILogger<UnitCreateCommandHandler> logger)
        {
            this.unitService = unitService;
            this.logger = logger;
        }

        /// <summary>
        /// 单位添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(UnitCreateCommand request, CancellationToken cancellationToken)
        {
            var entity = new Unit()
            {
                CompanyId = request.CompanyId,
                CompanyNode = request.CompanyNode,
                CompanyName = request.CompanyName,
                CompanyLogo = request.CompanyLogo,
                CompanyLabel = request.CompanyLabel,
                CompanyAbbreviation = request.CompanyAbbreviation,
                AccountingUnit = request.AccountingUnit,
                Addr = request.Addr,
                AreaId = request.AreaId,
                CompanyPhone = request.CompanyPhone,
                Describee = request.Describee,
                FinancePerson = request.FinancePerson,
                Isdelete = 0,
                LookPerson = request.LookPerson,
                ResponsibilitiesPerson = request.ResponsibilitiesPerson,
                ResponsiblePerson = request.ResponsiblePerson,


            };

            var list = await unitService.Add(entity);

            return Results<int>.DataResult(list);

        }
            




    }




}
